﻿using System;
using System.Collections.Generic;
using System.Data;

using Koonsoft.HYCRM.DAL;
using Koonsoft.HYCRM.Model;

namespace Koonsoft.HYCRM.BLL
{
    /// <summary>
    /// 
    /// </summary>
    public class CompanyBLL
    {
        private CompanyDAL _dal = null;

        protected CompanyDAL DAL
        {
            get
            {
                if (_dal == null)
                {
                    _dal = new CompanyDAL();
                }

                return _dal;
            }
        }

        /// <summary>
        /// 根据SerialNumber获取公司对象
        /// </summary>
        /// <param name="serialNumber">公司序号</param>
        /// <returns></returns>
        public Model.Company GetCompanyBySerialNumber(string serialNumber)
        {
            return DAL.GetCompanyBySerialNumber(serialNumber);
        }

        /// <summary>
        /// 根据companyId获取公司对象
        /// </summary>
        /// <param name="companyId"></param>
        /// <returns></returns>
        public Company GetCompanyByCompanyid(string companyId)
        {
            return DAL.GetCompanyByCompanyid(companyId);
        }

        /// <summary>
        /// 获取分页公司信息
        /// </summary>
        /// <param name="pageSize"></param>
        /// <param name="pageIndex"></param>
        /// <param name="recordCount"></param>
        /// <returns></returns>
        public DataTable GetCompaniesByPager(string orderStart, string orderEnd, string englishName, string chineseName,
                            string companyid, int regionID, int pageSize, int pageIndex, out int recordCount)
        {
            return DAL.GetCompaniesByPager(orderStart, orderEnd, englishName, chineseName, companyid, regionID, pageSize, pageIndex, out recordCount);
        }

           /// <summary>
        /// 获取分页的公司数据(快递)
        /// </summary>
        /// <param name="pageSize"></param>
        /// <param name="pageIndex"></param>
        /// <param name="recordCount"></param>
        /// <param name="orderStart"></param>
        /// <returns></returns>
        public DataTable GetCompaniesByPagerByKuaiDi(string englishName, string chineseName,
                            string companyid, int regionID, int pageSize, int pageIndex, out int recordCount)
        {
            return DAL.GetCompaniesByPagerByKuaiDi(englishName, chineseName, companyid, regionID, pageSize, pageIndex, out recordCount);
        }


        /// <summary>
        /// 删除公司（需要同时删除相关的客人和订单才对，但目前未实现）
        /// </summary>
        /// <param name="companySerialNumber"></param>
        public void Remove(string companySerialNumber)
        {
            DAL.Remove(companySerialNumber);
        }

        /// <summary>
        /// 根据订单编号获取公司信息
        /// </summary>
        /// <param name="orderID"></param>
        /// <returns></returns>
        public CompanyInfo GetCompanyInfoByOrderID(string orderID)
        {
            return DAL.GetCompanyInfoByOrderID(orderID);
        }

        /// <summary>
        /// 文件处理时更新公司资料
        /// </summary>
        /// <param name="companyID"></param>
        /// <param name="englishName"></param>
        /// <param name="chineseName"></param>
        /// <param name="serialNumber"></param>
        /// <param name="registerDate"></param>
        public void FileHandleByCompanySerialNumber(string companyID, string englishName, string chineseName, string serialNumber, string registerDate)
        {
            DAL.FileHandleByCompanySerialNumber(companyID, englishName, chineseName, serialNumber, registerDate);
        }

        /// <summary>
        /// 根据公司ID获取公司信息
        /// </summary>
        /// <param name="companyID"></param>
        /// <returns></returns>
        public CompanyInfo GetCompanyInfoByCompanyIDAndRegionID(string companyID, string regionID)
        {
            return DAL.GetCompanyInfoByCompanyIDAndRegionID(companyID, regionID);
        }


        /// <summary>
        /// 变更公司状态
        /// </summary>
        /// <param name="companySerialNumber"></param>
        /// <param name="companyStatus"></param>
        public void UpdateCompanyStatus(string companySerialNumber, int companyStatus)
        {
            DAL.UpdateCompanyStatus(companySerialNumber, companyStatus);
        }


        /// <summary>
        /// 变更公司注册日期
        /// </summary>
        /// <param name="registerDate"></param>
        /// <param name="companySerialNumber"></param>
        public void UpdateRegisterDate(string registerDate, string companySerialNumber)
        {
            DAL.UpdateRegisterDate(registerDate, companySerialNumber);
        }

        /// <summary>
        /// 根据公司ID获取董事信息
        /// </summary>
        /// <param name="companyId"></param>
        /// <returns></returns>
        public List<CompanyDiectorsEntity> GetCompanyDiectors(string companyId)
        {
            return DAL.GetCompanyDiectors(companyId);
        }

        /// <summary>
        /// 新增/修改 董事信息
        /// </summary>
        /// <param name="companyId"></param>
        /// <param name="directorName"></param>
        /// <param name="proportion"></param>
        public void CreateCompanyDiectors(string companyId, List<CompanyDiectorsEntity> dt)
        {
            DAL.ClearCompanyDiectors(companyId);

            if (dt.Count > 0)
            {
                foreach (var dataRow in dt)
                {
                    DAL.CreateCompanyDiectors(companyId, dataRow.DirectorName, dataRow.EnglishName, Convert.ToDouble(dataRow.Proportion), dataRow.ISDirector.ToString());
                }
            }
        }

        /// <summary>
        /// 根据OrderId获取核数内容
        /// </summary>
        /// <param name="companyId"></param>
        /// <returns></returns>
        public CompanyAuditorsEntity GetCompanyAuditorsEntityByOrderId(string OrderId)
        {
            return DAL.GetCompanyAuditorsEntityByOrderId(OrderId);
        }

        public void UpdateCompanyAuditorsStatuc(string OrderId, int Status, string loginName)
        {
            DAL.UpdateCompanyAuditorsStatuc(OrderId, Status, loginName);

        }

        /// <summary>
        /// 核数基本信息
        /// </summary>
        public void CreateCompanyAuditors(CompanyAuditorsEntity entity)
        {
            DAL.CreateCompanyAuditors(entity);
        }

        /// <summary>
        /// 查询核数状态变更日志
        /// </summary>
        public DataTable CompanyAuditorsStatusLog(string OrderId)
        {
            return DAL.CompanyAuditorsStatusLog(OrderId);
        }
    }
}
